import { Module } from '@nestjs/common';
import { LoginModule } from './login/login.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersModule } from './users/users.module';
import { AuthModule } from './auth/auth.module';

import { ArticleModule } from './article/article.module';
import { CacheService } from './cache/cache.service';
import { RedisModule, RedisModuleOptions } from 'nestjs-redis';
import { TasksModule } from './tasks/tasks.module';
import { ScheduleModule } from '@nestjs/schedule';
import { AdminuserModule } from './adminuser/adminuser.module';
import { RoleModule } from './role/role.module';
import { AuthorityModule } from './authority/authority.module';
import { RoleService } from './role/role.service';

const options: RedisModuleOptions = {
  port: 6379,
  host:
    process.env.npm_lifecycle_event === 'start:dev' ? '127.0.0.1' : 'redis-app',
  password: '',
  db: 0,
  name: 'cache',
};

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host:
        process.env.npm_lifecycle_event === 'start:dev'
          ? '127.0.0.1'
          : 'mysql-app',
      port: 3306,
      username: 'root',
      password: '12345678',
      cache: true,
      database: 'nest', // 数据库名称
      entities: [__dirname + '/**/*.entity{.ts,.js}'], // 扫描本项目中.entity.ts或者.entity.js的文件
      synchronize: true, // 定义数据库表结构与实体类字段同步(这里一旦数据库少了字段就会自动加入,根据需要来使用)
    }),
    RedisModule.register(options),
    ScheduleModule.forRoot(),
    ArticleModule,
    LoginModule,
    UsersModule,
    AuthModule,
    TasksModule,
    AdminuserModule,
    RoleModule,
    AuthorityModule,
  ],
  providers: [CacheService],
  controllers: [],

  //  controllers: [LoginController],
})
export class AppModule {}
